package com.sinodata.bsm.cicp.finder.sco;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

/**
 * 
 * <p>
 * Description: SCO-Unix CPU发现程序
 * 程序返回：
 *    CPU主频，CPUID，CPU类型。
 * 
 * 其中 CPU主频 = "N/A",CPU主频 = "N/A".
 * </p>
 *
 * @author liulibo
 * @version 1.0

 * <p>
 * History: 
 *
 * Date                     Author         Version     Description
 * ---------------------------------------------------------------------------------
 * 2012-12-26 AM 10:21:29   liulibo        1.0         To create
 * </p>
 *
 * @since 
 * @see
 */
public class ScoCPU extends ScoFinder {

    private static final Logger logger = Logger.getLogger(ScoCPU.class);

    private static final String CMDSTR = "uname -X| awk '{if($1~/^NumCPU/) print $3}' ";

    @SuppressWarnings("unchecked")
    @Override
    public List<String[]> find(String ip, Map params) {
        List<String[]> list = new ArrayList<String[]>();
        String[] cpuRes = null;
        try {
            List<String> tempList = getResultStrFromCommand(CMDSTR, ip);
            if (tempList.size() < 1) {
                return list;
            }
            String str = tempList.get(0);

            int cpuTotNum = Integer.parseInt(str);
            for (int i = 0; i < cpuTotNum; i++) {
                cpuRes = new String[6];
                list.add(cpuRes);
                cpuRes[0] = i + "";
                cpuRes[1] = "CPU" + i;
                cpuRes[2] = getHostName(ip) + " CPU " + i;
                cpuRes[3] = "N/A"; //CPU主频
                cpuRes[4] = i + ""; //CPUID
                cpuRes[5] = "N/A"; //CPU类型
            }
            return list;
        } catch (Exception e) {
            logger.error("failed to fand Sco CPU", e);
        }
        return null;
    }

}
